package Test;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 沈明月
 * Date: 2023-06-29
 * Time: 17:26
 */

//静态内部类（不需要借助外部类可以直接访问的内部类）
class OuterClass2{
    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    static class InnerClass {
            public int data4 = 4;
            public int data5 = 5;
            public static int data6 = 6;

            public void test(){
                //如何在静态内部类中访问外部类的非静态的数据成员：
                OuterClass2 outerClass2 = new OuterClass2();
                System.out.println(outerClass2.data1);

                System.out.println(data4);
                System.out.println(data5);
                System.out.println(data6);
                System.out.println("内部类的test方法");
            }

    }
}
public class Test3 {

    public void func(){
        //局部内部类：只能在方法内部使用，不能被访问限定符修饰
        class Inner{
            public int data1 = 1;
        }
        Inner inner = new Inner();
        System.out.println(inner.data1);
    }
    public static void main(String[] args) {
        //如何获取静态内部类对象：创建静态类内部对象时不需要先创建外部类对象
        OuterClass2.InnerClass innerClass = new OuterClass2.InnerClass();
        innerClass.test();
    }
}
